package tongcheng.com.tongcheng.ui.yemian.shenfen.activity;

import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import butterknife.Bind;
import butterknife.ButterKnife;
import tongcheng.com.tongcheng.R;
import tongcheng.com.tongcheng.base.BaseActivity;
import tongcheng.com.tongcheng.base.fuwu.FuWuAreaActivity;
import tongcheng.com.tongcheng.base.fuwu.FuWuLeiXingActivity;
import tongcheng.com.tongcheng.utils.Setting;
import tongcheng.com.tongcheng.utils.ShowToast;

public class InstallPeopleActivity extends BaseActivity {

    @Bind(R.id.back)
    ImageView mBack;
    @Bind(R.id.title)
    TextView mTitle;
    @Bind(R.id.install_ll1)
    LinearLayout mInstallLl1;
    @Bind(R.id.install_ll2)
    LinearLayout mInstallLl2;
    @Bind(R.id.install_next)
    Button mInstallNext;

    @Bind(R.id.title_bar)
    RelativeLayout mBg;
    @Bind(R.id.back_text)
    TextView mBackText;
    @Bind(R.id.title_line)
    View mTitleLine;
    @Bind(R.id.install_name)
    EditText mInstallName;
    @Bind(R.id.install_shenfenno)
    EditText mInstallShenfenno;
    @Bind(R.id.install_phone)
    EditText mInstallPhone;
    @Bind(R.id.install_address)
    EditText mInstallAddress;
    @Bind(R.id.install_fuwuleixing)
    TextView mInstallFuwuleixing;
    @Bind(R.id.install_fuwuarea)
    TextView mInstallFuwuarea;

    @Override
    public Integer initResid() {

        return R.layout.activity_install_people;
    }

    @Override
    public void initCreate(Bundle savedInstanceState) {
        Setting.setTemp(0);
        settitlebar(mBg);
        mTitle.setText("认证信息");

        mInstallNext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (TextUtils.isEmpty(mInstallName.getText().toString().trim())) {
                    ShowToast.showToast("请输入姓名");
                } else if (TextUtils.isEmpty(mInstallShenfenno.getText().toString().trim())) {
                    ShowToast.showToast("请输入身份证号码");
                }else if (TextUtils.isEmpty(mInstallPhone.getText().toString().trim())) {
                    ShowToast.showToast("请输入手机号码");
                }else if (TextUtils.isEmpty(mInstallAddress.getText().toString().trim())) {
                    ShowToast.showToast("请输入居住地址");
                } else {
                    Setting.setUserName(mInstallName.getText().toString().trim());
                    Setting.setShenFenNo(mInstallShenfenno.getText().toString().trim());
                    Setting.setLianXiDianHua(mInstallPhone.getText().toString().trim());
                    Setting.setAddress(mInstallAddress.getText().toString().trim());
                    Setting.setFuwuLeixing1(mInstallFuwuleixing.getText().toString().trim());
                    Setting.setFuwuArea1(mInstallFuwuarea.getText().toString().trim());
                    startactivity(InstallPeopleActivity.this, InstallUpLoadPic.class);
                }




            }
        });

        mBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        mInstallFuwuleixing.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startactivity(InstallPeopleActivity.this, FuWuLeiXingActivity.class);
            }
        });

        mInstallFuwuarea.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startactivity(InstallPeopleActivity.this, FuWuAreaActivity.class);
            }
        });




    }


    @Override
    protected void onResume() {
        super.onResume();
        StringBuffer sb1 = new StringBuffer();
        Log.e("area", Setting.getFuwuArea()+Setting.getTemp());
        if (!TextUtils.isEmpty(Setting.getFuwuArea())) {
            if (Setting.getTemp() != 0) {
                mInstallFuwuarea.setTextColor(ContextCompat.getColor(this,R.color.dan_bloack));
                mInstallFuwuarea.setText(Setting.getFuwuArea());

            }
        }

        if (!TextUtils.isEmpty(Setting.getFuwuLeixing())) {
            if (Setting.getTemp() != 0) {
                mInstallFuwuleixing.setTextColor(ContextCompat.getColor(this,R.color.dan_bloack));
                mInstallFuwuleixing.setText(Setting.getFuwuLeixing());

            }
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Setting.setTemp(0);
        Setting.setFuwuArea("");
        Setting.setFuwuLeixing("");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
